﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TotalSystems.DataAccess;
using TotalSystems.Business.Public;

namespace TotalSystems.Business.Store
{
    public class DegreeImportantStuffRepository
    {
        TSContext _context = new TSContext();
        FinancialYearRepository financialYearRepository = new Public.FinancialYearRepository();

        #region Select
        public IEnumerable<STR_DegreeImportantStuff> GetDegreeImportantStuff()
        {
            try
            {
                return _context.STR_DegreeImportantStuff;
            }
            catch (Exception ex)
            {

                return null;
            }
            
        }

        #endregion

        #region Insert

        public void InsertDegreeImportantStuff(STR_DegreeImportantStuff sTR_DegreeImportantStuff)
        {
            sTR_DegreeImportantStuff.ACC_Fy_ID_fk = financialYearRepository.GetACC_FinancialYearActive().Select(x => x.ACC_Fy_ID_fk).First();
            _context.AddToSTR_DegreeImportantStuff(sTR_DegreeImportantStuff);
            _context.SaveChanges();
        }
        
        #endregion

        #region Update

        public void UpdateDegreeImportantStuff(STR_DegreeImportantStuff sTR_DegreeImportantStuff)
        {
            var q = _context.STR_DegreeImportantStuff.FirstOrDefault(x => x.STR_Dis_ID == sTR_DegreeImportantStuff.STR_Dis_ID);
            q.STR_Dis_Name = sTR_DegreeImportantStuff.STR_Dis_Name;
            _context.STR_DegreeImportantStuff.ApplyCurrentValues(q);
            _context.SaveChanges();
        }

        #endregion
    }
}
